import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class 回文日期 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String n = sc.nextLine();
        //1.转换输入的回文日期数字为日期
        //1.1定义要转化为LocalDate的模式
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
        //对传入的字符串进行转化
        LocalDate date = LocalDate.parse(n, format);
        //保证是下一个回文日期,所以进行+1
        date= date.plusDays(1);
        //复制这个日期用于判断ababbaba型回文日期
        LocalDate newDate=date;
        //判断是否是回文日期
        while (!isReverse(date)){
            date= date.plusDays(1);
        }
        System.out.println(date.format(format));
        //判断是否是 ABABBABA型回文日期
        while (!isAB(newDate)){
            newDate=newDate.plusDays(1);
        }
        System.out.println(newDate.format(format));
    }
    public static boolean isAB(LocalDate date){
        //A0 B1 A2 B3 B4 A5 B6 A7
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
        String str = date.format(format);
        char[] c = str.toCharArray();
        return c[0]==c[2]&&c[1]==c[3]&&c[2]==c[5]
                &&c[3]==c[4]&&c[5]==c[7]&&c[4]==c[6];
    }
    public static boolean isReverse(LocalDate date){
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
        String n = date.format(format);
        StringBuilder sb=new StringBuilder(n);
        return sb.toString().contentEquals(sb.reverse());
    }
}
